package com.blog.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import com.blog.myUtils.DateTime;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * <p>
 *
 * </p>
 *
 * @author mars123
 * @since 2019-07-02
 */
public class Product extends Model<Product> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private Integer uid;
    private String name;
    private Integer type;
    private String sku;
    private String spu;
    @TableField("img_main")
    private String imgMain;
    private String content;
    /**
     * 原价
     */
    private BigDecimal price;
    /**
     * 售价
     */
    @TableField("final_price")
    private BigDecimal finalPrice;
    /**
     * 库存
     */
    private Integer qty;
    private String size;
    @TableField("created_at")
    private Integer createdAt;
    @TableField("updated_at")
    private Integer updatedAt;

    public String getTypeName() {
        return type != null ? new ProductType().selectById(type).getName() : "-";
    }


    public User getUser() {
        return uid != null ? new User().selectById(uid) : null;
    }

    public String getCreatedTime() {
        return createdAt == null ? "-" : DateTime.format(createdAt);
    }

    public String getUpdatedTime() {
        return updatedAt == null ? "-" : DateTime.format(updatedAt);
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getSku() {
        return sku;
    }

    public void setSku(String sku) {
        this.sku = sku;
    }

    public String getSpu() {
        return spu;
    }

    public void setSpu(String spu) {
        this.spu = spu;
    }

    public String getImgMain() {
        return imgMain;
    }

    public void setImgMain(String imgMain) {
        this.imgMain = imgMain;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getFinalPrice() {
        return finalPrice;
    }

    public void setFinalPrice(BigDecimal finalPrice) {
        this.finalPrice = finalPrice;
    }

    public Integer getQty() {
        return qty;
    }

    public void setQty(Integer qty) {
        this.qty = qty;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public Integer getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Integer createdAt) {
        this.createdAt = createdAt;
    }

    public Integer getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Integer updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", uid=" + uid +
                ", name=" + name +
                ", type=" + type +
                ", sku=" + sku +
                ", spu=" + spu +
                ", imgMain=" + imgMain +
                ", content=" + content +
                ", price=" + price +
                ", finalPrice=" + finalPrice +
                ", qty=" + qty +
                ", size=" + size +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                "}";
    }
}
